package com.example.litemall.admin.api.service.impl;

import com.example.litemall.admin.api.domain.LitemallAdmin;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.example.litemall.admin.api.mapper.LitemallAdminMapper;
import com.example.litemall.admin.api.service.LitemallAdminService;
import tk.mybatis.mapper.entity.Example;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class LitemallAdminServiceImpl implements LitemallAdminService{

    @Resource
    private LitemallAdminMapper litemallAdminMapper;

    @Override
    public List<LitemallAdmin> getAdminByUsername(String name) {
        Example example = new Example(LitemallAdmin.class);
        example.or().andEqualTo("username",name).andEqualTo("deleted",false);
        List<LitemallAdmin> litemallAdmins = litemallAdminMapper.selectByExample(example);
        return litemallAdmins;
    }

    @Override
    public void updateAdmin(LitemallAdmin admin) {
        admin.setUpdateTime(LocalDateTime.now());
        litemallAdminMapper.updateByPrimaryKeySelective(admin);
    }
}
